---
export interface Props {
  prev?: {
    title: string;
    href: string;
  };
  next?: {
    title: string;
    href: string;
  };
}

const { prev, next } = Astro.props;

const getNavigationClass = () => {
  if (prev && next) return 'has-both';
  if (prev && !next) return 'prev-only';
  if (!prev && next) return 'next-only';
  return '';
};
---

<div class={`tutorial-navigation ${getNavigationClass()}`}>
  {prev && (
    <a href={prev.href} class="tutorial-nav-link prev">
      <div class="nav-content">
        <div class="nav-header">
          <svg class="arrow" viewBox="0 0 24 24" fill="none">
            <path d="M15 18L9 12L15 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
          </svg>
          <span class="nav-label">Previous</span>
        </div>
        <span class="nav-title">{prev.title}</span>
      </div>
    </a>
  )}
  
  {next && (
    <a href={next.href} class="tutorial-nav-link next">
      <div class="nav-content">
        <div class="nav-header">
          <span class="nav-label">Next</span>
          <svg class="arrow" viewBox="0 0 24 24" fill="none">
            <path d="M9 18L15 12L9 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
          </svg>
        </div>
        <span class="nav-title">{next.title}</span>
      </div>
    </a>
  )}
</div>

<style>
  .tutorial-navigation {
    display: flex;
    gap: 1rem;
    margin: 2rem 0;
  }

  .tutorial-navigation.has-both {
    justify-content: space-between;
  }

  .tutorial-navigation.prev-only {
    justify-content: flex-start;
  }

  .tutorial-navigation.next-only {
    justify-content: flex-end;
  }

  .tutorial-nav-link {
    display: flex;
    padding: 1rem 1.5rem;
    border: 1px solid var(--sl-color-gray-5);
    border-radius: 0.5rem;
    text-decoration: none;
    color: var(--sl-color-text);
    background: var(--sl-color-bg-nav);
    transition: all 0.2s ease;
    flex: 1;
    max-width: 45%;
    min-height: 80px;
  }

  .tutorial-nav-link:hover {
    border-color: var(--sl-color-accent);
    background: var(--sl-color-bg-sidebar);
    transform: translateY(-2px);
  }

  .tutorial-navigation.prev-only .tutorial-nav-link,
  .tutorial-navigation.next-only .tutorial-nav-link {
    flex: 0 0 auto;
    width: 45%;
    max-width: 45%;
  }

  .nav-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
  }

  .tutorial-nav-link.prev .nav-content {
    align-items: flex-start;
  }

  .tutorial-nav-link.next .nav-content {
    align-items: flex-end;
  }

  .nav-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .nav-label {
    font-size: 0.875rem;
    color: var(--sl-color-text-accent);
    font-weight: 500;
  }

  .nav-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--sl-color-text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
  }

  .arrow {
    width: 1.25rem;
    height: 1.25rem;
    color: var(--sl-color-text-accent);
    transition: color 0.2s ease;
  }

  .tutorial-nav-link:hover .arrow {
    color: var(--sl-color-accent);
  }

  @media (max-width: 768px) {
    .tutorial-navigation {
      flex-direction: column;
      gap: 0.75rem;
    }

    .tutorial-nav-link {
      max-width: 100%;
    }

    .tutorial-nav-link.next {
      margin-left: 0;
    }
  }
</style>